Skip to content

Conversation

stephenquan
Copy link
Contributor

@stephenquan stephenquan commented Jun 16, 2025

Description of Change

Parse a double using InvariantCulture to avoid issues when CurrentCulture changes, such as to 'ar-AR'.

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (omitted, since this is a minor change)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: (no change)

Additional information

None


bool ParsePrimary()
{
if (ParsePattern(EvaluateNumberPattern()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to turn on the CA1305 analyzer in the project to avoid similar bugs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MartyIX based on your feedback, I applied the CA1305 analyzer and found multiple conversions in MathExpression.shared.cs that needed updates to satisfy the analyzer. After the changes all unit tests for the math converters still passed.

The CA1305 analyzer also picked up new issues which isn't part of the scope of this PR. Would you like me to create split 3 issues to look? (Camera CA1305, SpeechToText CA1305, Badge CA1305)?

F:\Maui\src\CommunityToolkit.Maui.Camera\CameraInfo.shared.cs(99,4): error CA1305: The behavior of 'StringBuilder.Append(ref StringBuilder.AppendInterpolatedStringHandler)' could vary based on the current user's locale settings. Replace this call in 'CameraInfo.ToString()' with a call to 'StringBuilder.Append(IFormatProvider, ref StringBuilder.AppendInterpolatedStringHandler)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)
F:\Maui\src\CommunityToolkit.Maui.Camera\CameraInfo.shared.cs(99,4): error CA1305: The behavior of 'StringBuilder.Append(ref StringBuilder.AppendInterpolatedStringHandler)' could vary based on the current user's locale settings. Replace this call in 'CameraInfo.ToString()' with a call to 'StringBuilder.Append(IFormatProvider, ref StringBuilder.AppendInterpolatedStringHandler)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)
F:\Maui\src\CommunityToolkit.Maui.Camera\CameraInfo.shared.cs(99,4): error CA1305: The behavior of 'StringBuilder.Append(ref StringBuilder.AppendInterpolatedStringHandler)' could vary based on the current user's locale settings. Replace this call in 'CameraInfo.ToString()' with a call to 'StringBuilder.Append(IFormatProvider, ref StringBuilder.AppendInterpolatedStringHandler)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)
F:\Maui\src\CommunityToolkit.Maui.Camera\CameraInfo.shared.cs(99,4): error CA1305: The behavior of 'StringBuilder.Append(ref StringBuilder.AppendInterpolatedStringHandler)' could vary based on the current user's locale settings. Replace this call in 'CameraInfo.ToString()' with a call to 'StringBuilder.Append(IFormatProvider, ref StringBuilder.AppendInterpolatedStringHandler)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)
F:\Maui\src\CommunityToolkit.Maui.Camera\CameraInfo.shared.cs(99,4): error CA1305: The behavior of 'StringBuilder.Append(ref StringBuilder.AppendInterpolatedStringHandler)' could vary based on the current user's locale settings. Replace this call in 'CameraInfo.ToString()' with a call to 'StringBuilder.Append(IFormatProvider, ref StringBuilder.AppendInterpolatedStringHandler)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)
F:\Maui\src\CommunityToolkit.Maui.Core\Essentials\SpeechToText\OfflineSpeechToTextImplementation.android.cs(188,56): error CA1305: The behavior of 'int.ToString()' could vary based on the current user's locale settings. Replace this call in 'RecognitionSupportCallback.OnError(int)' with a call to 'int.ToString(IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)
F:\Maui\src\CommunityToolkit.Maui.Core\Essentials\Badge\BadgeImplementation.windows.cs(22,40): error CA1305: The behavior of 'uint.ToString()' could vary based on the current user's locale settings. Replace this call in 'BadgeImplementation.SetCount(uint)' with a call to 'uint.ToString(IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Build failed with 7 error(s) and 81 warning(s) in 3.8s

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in no position to say what you should do or not, I'm just a random passerby :)) However, I believe it would be a nice new PR or PRs1 to avoid cramming this PR.

Footnotes

  1. If the number of necessary changes is small, then probably just one PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MartyIX, as per your feedback, I have created a new split issue #2744 to avoid cramming this PR.

Copy link
Collaborator

@VladislavAntonyuk VladislavAntonyuk Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can change the pattern to something like this:

@"^-?\d+[.,]?\d*$"

It should match:

  • 123
  • -123.45
  • -123,45

@dotnet-policy-service dotnet-policy-service bot added stale The author has not responded in over 30 days help wanted This proposal has been approved and is ready to be implemented labels Jul 24, 2025
@Copilot Copilot AI review requested due to automatic review settings October 15, 2025 23:01
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@TheCodeTraveler TheCodeTraveler enabled auto-merge (squash) October 15, 2025 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted This proposal has been approved and is ready to be implemented stale The author has not responded in over 30 days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] MathExpressionConverter doesn't support negative numbers when in Arabic (ar_AR)

5 participants